﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace XDesigner.Development.Controls
{
    public partial class dlgCopy : Form
    {
        public dlgCopy()
        {
            InitializeComponent();
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }


        private CopyOptions _InputCopyOptions = null;

        public CopyOptions InputCopyOptions
        {
            get { return _InputCopyOptions; }
            set { _InputCopyOptions = value; }
        }

        private void dlgCopy_Load(object sender, EventArgs e)
        {
            if (_InputCopyOptions == null)
            {
                _InputCopyOptions = new CopyOptions();
            }
            rdoSolution.Checked = _InputCopyOptions.Type == CopyType.Solution;
            rdoProject.Checked = _InputCopyOptions.Type == CopyType.Project;
            txtOutDirectory.Text = _InputCopyOptions.OutputDirectory;
            chkRemoveVSSInfo.Checked = _InputCopyOptions.RemoveVSSInfo;
            chkResetFileAttribute.Checked = _InputCopyOptions.ResetFileAttribute;
            chkClearOutputDirectory.Checked = _InputCopyOptions.ClearOutputDirectory;
            chkRemoveComment.Checked = _InputCopyOptions.RemoveCommment;
            txtHeaderComment.Text = _InputCopyOptions.HeaderComment;
            chkPreserveDocumentComment.Checked = _InputCopyOptions.PreserveDocumentComment;
            chkRemoveComment_CheckedChanged(null, null);
        }

        private void btnBrowseDirectory_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog dlg = new FolderBrowserDialog())
            {
                dlg.SelectedPath = txtOutDirectory.Text;
                dlg.ShowNewFolderButton = true;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    txtOutDirectory.Text = dlg.SelectedPath;
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string dir = txtOutDirectory.Text.Trim();
            if (System.IO.Directory.Exists(dir) == false )
            {
                MessageBox.Show(this, string.Format(DevStrings.DirectoryNotExist_Name, dir) , this.Text );
                return;
            }
            if (rdoProject.Checked)
            {
                _InputCopyOptions.Type = CopyType.Project;
            }
            else if (rdoSolution.Checked)
            {
                _InputCopyOptions.Type = CopyType.Solution;
            }
            _InputCopyOptions.OutputDirectory = dir;
            _InputCopyOptions.ResetFileAttribute = chkResetFileAttribute.Checked;
            _InputCopyOptions.RemoveVSSInfo = chkRemoveVSSInfo.Checked;
            _InputCopyOptions.ClearOutputDirectory = chkClearOutputDirectory.Checked;
            _InputCopyOptions.RemoveCommment = chkRemoveComment.Checked;
            _InputCopyOptions.HeaderComment = txtHeaderComment.Text;
            _InputCopyOptions.PreserveDocumentComment = chkPreserveDocumentComment.Checked;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void chkRemoveComment_CheckedChanged(object sender, EventArgs e)
        {
            chkPreserveDocumentComment.Enabled = chkRemoveComment.Checked;
        }
         
    }
}
